package com.biz.primus.ms.commodity.api;

import com.biz.primus.base.vo.ProductFieldVo;
import com.biz.primus.commodity.vo.ExtendDetailVo;
import com.biz.primus.commodity.vo.ExtendQueryVo;
import com.biz.primus.commodity.vo.ExtendVo;
import com.biz.primus.common.vo.SpringPageVO;
import com.biz.primus.ms.base.api.BaseApiController;
import com.biz.primus.ms.commodity.service.backend.ExtendService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("soa/extendService")
public class ExtendApiController extends BaseApiController {

    @Autowired
    private ExtendService extendService;

    @ApiOperation("创建扩展属性")
    @PostMapping("create")
    void create(@RequestBody ExtendVo extendVo){
        extendService.createExtend(extendVo);
    }

    @ApiOperation("更新扩展属性")
    @PostMapping("update")
    void update(@RequestParam("extendId") String extendId, @RequestBody ExtendVo extendVo){
        extendService.updateExtend(Long.valueOf(extendId),extendVo);
    }

    @ApiOperation("后台查找扩展属性")
    @PostMapping("findAll")
    SpringPageVO<ExtendDetailVo> findAll(@RequestBody ExtendQueryVo queryVo){
        return extendService.findExtends(queryVo);
    }

    @ApiOperation("删除扩展属性,物理删除")
    @PostMapping("delete")
    void delete(@RequestParam("extendId") String extendId,@RequestParam("delUser") String delUser){
        extendService.delExtend(Long.valueOf(extendId),delUser);
    }

    @ApiOperation("获取extend详情")
    @GetMapping("findExtendById")
    ExtendDetailVo findExtendById(@RequestParam("extendId") Long extendId){
        return extendService.findExtendById(extendId);
    }

    @ApiOperation("通过分类Id 获取扩展属性（静态）")
    @GetMapping("findFieldByCategoryId")
    List<ProductFieldVo> findFieldByCategoryId(Long categoryId){
        return extendService.findFieldByCategoryId(categoryId);
    }


}
